home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / zaccaria.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  6KB  |  211 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13.  
  14. unsigned char *zaccaria_attributesram;
  15.  
  16. static struct rectangle spritevisiblearea =
  17. {
  18.     2*8+1, 29*8-1,
  19.     2*8, 30*8-1
  20. };
  21.  
  22.  
  23.  
  24. /***************************************************************************
  25.  
  26.   Convert the color PROMs into a more useable format.
  27.  
  28.  
  29. Here's the hookup from the proms (82s131) to the r-g-b-outputs
  30.  
  31.      Prom 9F        74LS374
  32.     -----------   ____________
  33.        12         |  3   2   |---680 ohm----| blue out
  34.        11         |  4   5   |---1k ohm-----|
  35.        10         |  7   6   |---820 ohm-------|
  36.         9         |  8   9   |---1k ohm--------| green out
  37.      Prom 9G      |          |                 |
  38.        12         |  13  12  |---1.2k ohm------|
  39.        11         |  14  15  |---820 ohm----------|
  40.        10         |  17  16  |---1k ohm-----------| red out
  41.         9         |  18  19  |---1.2k ohm---------|
  42.                   |__________|
  43.  
  44.  
  45. ***************************************************************************/
  46. void zaccaria_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  47. {
  48.     int i,j,k;
  49.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  50.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  51.  
  52.  
  53.     for (i = 0;i < Machine->drv->total_colors;i++)
  54.     {
  55.         int bit0,bit1,bit2;
  56.  
  57.  
  58.         /* I'm not sure, but I think that pen 0 must always be black, otherwise */
  59.         /* there's some junk brown background in Jack Rabbit */
  60.         if (((i % 64) / 8) == 0)
  61.         {
  62.             *(palette++) = 0;
  63.             *(palette++) = 0;
  64.             *(palette++) = 0;
  65.         }
  66.         else
  67.         {
  68.             /* red component */
  69.             bit0 = (color_prom[0] >> 3) & 0x01;
  70.             bit1 = (color_prom[0] >> 2) & 0x01;
  71.             bit2 = (color_prom[0] >> 1) & 0x01;
  72.             *(palette++) = 0x46 * bit0 + 0x53 * bit1 + 0x66 * bit2;
  73.             /* green component */
  74.             bit0 = (color_prom[0] >> 0) & 0x01;
  75.             bit1 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  76.             bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  77.             *(palette++) = 0x46 * bit0 + 0x53 * bit1 + 0x66 * bit2;
  78.             /* blue component */
  79.             bit0 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  80.             bit1 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  81.             *(palette++) = 0x53 * bit0 + 0x7b * bit1;
  82.         }
  83.  
  84.         color_prom++;
  85.     }
  86.  
  87.     /* There are 512 unique colors, which seem to be organized in 8 blocks */
  88.     /* of 64. In each block, colors are not in the usual sequential order */
  89.     /* but in interleaved order, like Phoenix. Additionally, colors for */
  90.     /* background and sprites are interleaved. */
  91.     for (i = 0;i < 8;i++)
  92.     {
  93.         for (j = 0;j < 4;j++)
  94.         {
  95.             for (k = 0;k < 8;k++)
  96.             {
  97.                 /* swap j and k to make the colors sequential */
  98.                 COLOR(0,32 * i + 8 * j + k) = 64 * i + 8 * k + 2*j;
  99.             }
  100.         }
  101.     }
  102.     for (i = 0;i < 8;i++)
  103.     {
  104.         for (j = 0;j < 4;j++)
  105.         {
  106.             for (k = 0;k < 8;k++)
  107.             {
  108.                 /* swap j and k to make the colors sequential */
  109.                 COLOR(1,32 * i + 8 * j + k) = 64 * i + 8 * k + 2*j+1;
  110.             }
  111.         }
  112.     }
  113. }
  114.  
  115.  
  116.  
  117. WRITE_HANDLER( zaccaria_attributes_w )
  118. {
  119.     if ((offset & 1) && zaccaria_attributesram[offset] != data)
  120.     {
  121.         int i;
  122.  
  123.  
  124.         for (i = offset / 2;i < videoram_size;i += 32)
  125.             dirtybuffer[i] = 1;
  126.     }
  127.  
  128.     zaccaria_attributesram[offset] = data;
  129. }
  130.  
  131.  
  132.  
  133. /***************************************************************************
  134.  
  135.   Draw the game screen in the given osd_bitmap.
  136.   Do NOT call osd_update_display() from this function, it will be called by
  137.   the main emulation engine.
  138.  
  139. ***************************************************************************/
  140. void zaccaria_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  141. {
  142.     int offs;
  143.  
  144.  
  145.     /* for every character in the Video RAM, check if it has been modified */
  146.     /* since last time and update it accordingly. */
  147.     for (offs = videoram_size - 1;offs >= 0;offs--)
  148.     {
  149.         if (dirtybuffer[offs])
  150.         {
  151.             int sx,sy;
  152.  
  153.  
  154.             dirtybuffer[offs] = 0;
  155.  
  156.             sx = offs % 32;
  157.             sy = offs / 32;
  158.  
  159.             drawgfx(tmpbitmap,Machine->gfx[0],
  160.                     videoram[offs] + ((colorram[offs] & 0x03) << 8),
  161.                     4 * (zaccaria_attributesram[2 * (offs % 32) + 1] & 0x07)
  162.                             + ((colorram[offs] & 0x0c) >> 2),
  163.                     0,0,
  164.                     8*sx,8*sy,
  165.                     0,TRANSPARENCY_NONE,0);
  166.         }
  167.     }
  168.  
  169.  
  170.     /* copy the temporary bitmap to the screen */
  171.     {
  172.         int scroll[32];
  173.  
  174.  
  175.         for (offs = 0;offs < 32;offs++)
  176.             scroll[offs] = -zaccaria_attributesram[2 * offs];
  177.  
  178.         copyscrollbitmap(bitmap,tmpbitmap,0,0,32,scroll,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  179.     }
  180.  
  181.  
  182.     /* draw sprites */
  183.     /* TODO: sprites have 32 color codes, but we are using only 8. In Jack */
  184.     /* Rabbit the extra codes are all duplicates, but there is a quadruple */
  185.     /* of codes in Money Money which contains two different combinations. */
  186.  
  187.     /* TODO: sprite placement is not perfect, I made the Jack Rabbit mouth */
  188.     /* animation correct but this moves one pixel to the left the sprite */
  189.     /* which masks the holes when you fall in them. The hardware is probably */
  190.     /* similar to Amidar, but the code in the Amidar driver is not good either. */
  191.     for (offs = 0;offs < spriteram_2_size;offs += 4)
  192.     {
  193.         drawgfx(bitmap,Machine->gfx[1],
  194.                 (spriteram_2[offs + 2] & 0x3f) + (spriteram_2[offs + 1] & 0xc0),
  195.                 4 * (spriteram_2[offs + 1] & 0x07),
  196.                 spriteram_2[offs + 2] & 0x40,spriteram_2[offs + 2] & 0x80,
  197.                 spriteram_2[offs + 3] + 1,242 - spriteram_2[offs],
  198.                 &spritevisiblearea,TRANSPARENCY_PEN,0);
  199.     }
  200.  
  201.     for (offs = 0;offs < spriteram_size;offs += 4)
  202.     {
  203.         drawgfx(bitmap,Machine->gfx[1],
  204.                 (spriteram[offs + 1] & 0x3f) + (spriteram[offs + 2] & 0xc0),
  205.                 4 * (spriteram[offs + 2] & 0x07),
  206.                 spriteram[offs + 1] & 0x40,spriteram[offs + 1] & 0x80,
  207.                 spriteram[offs + 3] + 1,242 - spriteram[offs],
  208.                 &spritevisiblearea,TRANSPARENCY_PEN,0);
  209.     }
  210. }
  211.